package com.slg.android.listenbook.biz.home.moudle;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * User: Giotto
 * Date: 2015-03-25
 * Time: 14:35
 */
public class Channel implements Serializable {
    private String channelId;
    private String channelName;
    private String cateId;
    private String cate;
    private boolean isSelected = false;

    public static List<Channel> parseData(String json) {
        ArrayList<Channel> list = new ArrayList<>();
        try {
            JSONObject jsonObject = new JSONObject(json);
            JSONArray jsonArray = jsonObject.getJSONArray("channel_list");
            for (int i = 0; i < jsonArray.length(); i++) {
                JSONObject channel = jsonArray.getJSONObject(i);
                Channel c = new Channel();
                c.setChannelId(channel.getString("channel_id"));
                c.setChannelName(channel.getString("channel_name"));
                c.setCateId(channel.getString("cate_id"));
                c.setCate(channel.getString("cate"));
                list.add(c);
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return list;
    }

    @Override
    public String toString() {
        return "Channel{" +
                "channelId='" + channelId + '\'' +
                ", channelName='" + channelName + '\'' +
                ", cateId='" + cateId + '\'' +
                ", cate='" + cate + '\'' +
                '}';
    }

    public boolean isSelected() {
        return isSelected;
    }

    public void setSelected(boolean isSelected) {
        this.isSelected = isSelected;
    }

    public String getChannelId() {
        return channelId;
    }

    public void setChannelId(String channelId) {
        this.channelId = channelId;
    }

    public String getChannelName() {
        return channelName;
    }

    public void setChannelName(String channelName) {
        this.channelName = channelName;
    }

    public String getCateId() {
        return cateId;
    }

    public void setCateId(String cateId) {
        this.cateId = cateId;
    }

    public String getCate() {
        return cate;
    }

    public void setCate(String cate) {
        this.cate = cate;
    }

}
